// pages/person/address/index.js
const app = getApp()
import Toast from "../../../vant/weapp/toast/toast";
Page({
  data: {
    addressList: [],
    type: 0,
    isAddressList: true
  },
  onShow() {
    this.getAddressList()
  },
  onLoad(options) {
    this.setData({
      type: options.type
    })
  },
  choose(e) {
    if (this.data.type == 1) {
      wx.setStorageSync('address', e.currentTarget.dataset.data)
      wx.setStorageSync('add', 1)
      wx.navigateBack({
        delta: 1
      })
    }
  },
  getAddressList() {
    app.http.get(app.api.addressList, {}, (res) => {
      if (res.data == "") {
        this.setData({
          addressList: res.data.list,
          isAddressList: true
        })
      } else {
        this.setData({
          addressList: res.data.list,
          isAddressList: false
        })
      }
    })
  },
  change(e) {
    wx.navigateTo({
      url: "/pages/person/addressAdd/index?type=1&id=" + e.currentTarget.dataset.id,
    });
  },
  delete(e) {
    let id = e.currentTarget.dataset.id
    app.http.post(app.api.addressDel, {
      id
    }, (res) => {
      console.log(res)
      this.getAddressList()
    })

  },
  add() {
    const that = this
  
    wx.navigateTo({
      url: "/pages/person/addressAdd/index?type=0",
    });
  },

});